setopt HIST_IGNORE_ALL_DUPS
bindkey -v
WORDCHARS=${WORDCHARS//[\/]}
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)

ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
[ ! -d $ZINIT_HOME ] && mkdir -p "$(dirname $ZINIT_HOME)"
[ ! -d $ZINIT_HOME/.git ] && git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
source "${ZINIT_HOME}/zinit.zsh"

zinit light zsh-users/zsh-completions
zinit light zsh-users/zsh-syntax-highlighting
zinit light zsh-users/zsh-history-substring-search
zinit light zsh-users/zsh-autosuggestions
zinit light jeffreytse/zsh-vi-mode
zinit light Aloxaf/fzf-tab

autoload -U compinit && compinit

HISTSIZE=5000
HISTFILE=~/.zhistory
SAVEHIST=$HISTSIZE
HISTDUP=erase
setopt appendhistory
setopt sharehistory
setopt hist_ignore_space
setopt hist_ignore_all_dups
setopt hist_save_no_dups
setopt hist_ignore_dups
setopt hist_find_no_dups

zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*' menu no
zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm -w -w"
zstyle ':completion:complete:*:options' sort false
zstyle ':completion:*:descriptions' format "[%d]"

# user set
export EDITOR=/usr/bin/nvim
export TERMINAL=kitty

[ $(tty) = "/dev/tty1" ] && cd ~ && startx

source ~/.config/zsh/theme.zsh
source ~/.config/zsh/fzf.zsh

mcommands="$HOME/.config/zsh/utils"
for file in $(find "$mcommands" -maxdepth 1 -type f); do
  if [[ $file =~ \.zsh$ ]]; then
    source ${file}
  elif [[ $file =~ \.sh$ ]]; then
    name=${file:t:r}
    alias ${name}="bash ${file}"
  fi
done

_killall_processes(){
  local processes
  processes=($(ps -e -o comm= | sort -u))
  compadd "$@" -- $processes
}

compdef _killall_processes killall

# mu alias
alias vim='/usr/bin/nvim'
alias lg='lazygit'
alias ra='yazi'
alias c='clear'
alias s='neofetch'
alias sudo='sudo -E'
alias du='dust'
alias ls='ls --color=auto'
alias ll='ls -l'
alias mpv='mpv --geometry=1280x700'
